#!/usr/bin/env/ python
# -*- coding: utf-8 -*-

"""
@author: super
@software: PyCharm
@file: book
@time: 2022/1/27 11:21
"""
import os
from core.rest_client import RestClient
from commonon.read_data import ReadFileData

# 拿到封装的请求地址
BASE_PATH = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
data_file_path = os.path.join(BASE_PATH, "config", "setting.ini")
data = ReadFileData()
api_root_url = data.load_ini(data_file_path)["host"]["api_root_url"]

class Book(RestClient):
    '''书籍请求接口'''

    def __init__(self, api_root_url, **kwargs):
        super(Book, self).__init__(api_root_url, **kwargs)

    def all_books(self, **kwargs):
        '''获取所有书籍接口'''
        return self.get("/v1/api/books", **kwargs)

    def id_book(self, id, **kwargs):
        '''根据id查看一本书籍'''
        return self.get("/v1/api/book/{0}".format(id), **kwargs)

    def add_books(self, **kwargs):
        '''添加书籍'''
        return self.post("/v1/api/books", **kwargs)

    def update_books(self, id, json, **kwargs):
        '''修改书籍'''
        return self.put("/v1/api/book/{0}".format(id), json=json, **kwargs)

    def delete_book(self, id, **kwargs):
        '''删除书籍'''
        return self.delete("/v1/api/book/{0}".format(id), **kwargs)

book = Book(api_root_url)